package com.example.emailcraft.filter;

import com.example.emailcraft.interceptor.CurrentUserHolder;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import java.io.IOException;

/**
 * 确保线程上下文清理的过滤器
 */
@Component
public class CurrentUserCleanupFilter implements Filter {

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {
        try {
            chain.doFilter(request, response);
        } finally {
            // 确保任何情况下都清理上下文
            CurrentUserHolder.clear();
        }
    }
}
